package com.lovo.csc.service.impl;

import com.alibaba.fastjson.JSON;
import com.lovo.csc.entity.ReturnOrder;
import com.lovo.csc.mapper.ReturnOrderMapper;
import com.lovo.csc.service.IReturnOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lovo.dto.ReturnOrderDto;
import com.lovo.sscweb.dto.OrderDto;
import com.lovo.util.MQUtil;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * <p>
 * 前端传回需要审核退款的客户订单 服务实现类
 * </p>
 *
 * @author lovo
 * @since 2022-07-07
 */
@Service
public class ReturnOrderServiceImpl extends ServiceImpl<ReturnOrderMapper, ReturnOrder> implements IReturnOrderService {
    @Autowired
    RedisTemplate redisTemplate;
    @RabbitListener(queues =MQUtil.returnOrderQueue)
    public void getReturnOrder(Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag, String order) throws IOException {
        if (order == null ){
            return;
        }
        ReturnOrderDto orderDto = JSON.parseObject(order,ReturnOrderDto.class);
        //  用退货单编号作为键
        redisTemplate.opsForHash().put("returnOrder",orderDto.getReturngoodscode(),orderDto);
        channel.basicAck(tag,false);
    }

}
